package com.swu.education.util;

import java.io.*;

/**
 * Created by nana on 2018/3/23.
 */
public class TxtWrite {

  public void dealTextInfo(int activityId,int id,String userMes,String responseMes){
    try{
      String txtName = "File\\"+activityId+"_"+id+".txt";
      File file = new File(txtName);
      if(!file.exists()){
        file.createNewFile();
        BufferedWriter out = new BufferedWriter(new FileWriter(file));
        out.write("老师：你好，很高兴见到你<br>\r\n");
        out.write("学生："+userMes+"<br>\r\n");
        out.write("老师："+responseMes+"<br>\r\n");
        out.flush();
        out.close();
      }else {
        BufferedWriter out = new BufferedWriter(new FileWriter(file,true));
        out.write("学生："+userMes+"<br>\r\n");
        out.write("老师："+responseMes+"<br>\r\n");
        out.flush();
        out.close();
      }
    }catch (IOException e){
      e.printStackTrace();
    }
  }

 /* public void readTxt(int id) {
    try { // 防止文件建立或读取失败，用catch捕捉错误并打印，也可以throw

    *//* 读入TXT文件 *//*
      String txtName = "File\\"+activityId+"_"+id+".txt";
      File file = new File(txtName);
      InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file));//建立输入流对象

      BufferedReader br = new BufferedReader(inputStreamReader); // 建立一个对象，它把文件内容转成计算机能读懂的语言
      String line = "";
      line = br.readLine();
      while (line != null) {
        line = br.readLine(); // 一次读入一行数据
      }
    }catch (Exception e) {
      e.printStackTrace();
    }
  }*/
}
